#include "stdafx.h"
#include "emotionalmemory.h"
#include "goal_Defend.h"
#include "event.h"
using namespace BAA;


EmotionalMemory* BAA::Goal_Defend::AppraiseEvent( Event * event )
{
	return NULL;
}

float BAA::Goal_Defend::CalculateStateUtility( Agent * agent )
{

	
	// defend only useful if being attacked.
	if((*(ParentRole()->StringFloatProperties()))["TargetsUnderAttack"] > 0)
	{

		AgentProperties * props = ParentRole()->Self()->Properties();

		float anger =1- abs(mAngerPoint - (props->mAnger->GetValue() + (*(mRoleParent->Emotions()))["anger"]->GetValue())/2.0f);
		float fear = 1- abs(mFearPoint - (*(mRoleParent->Emotions()))["fear"]->GetValue());
		float honor = 1- abs(mHonorPoint - props->mHonor->Desire());

		float utility = (anger - fear + honor)/3.0f;

		return utility;
	}
	else
	{
		return -1;
	}
}

float BAA::Goal_Defend::CalculateUtilityForAction( Action * action )
{
	StringFloatMap * consequences = action->Consequences();
	float utility = (*consequences)["defend"];

	// ASSUME 

	// for the goals, check to see if the target is someone who this goal cares about.
	
	// quick check ( if the action is role parent is the goals role parent the true;
	if(action->RoleParent() == this->ParentRole())
	{
		return utility;
	}
	else
	{
		
		if(this->ParentRole()->TargetContainsAgent(action->GetTargets()))
			return utility;
		else
			return 0.0f;
	}
}